package com.cskaoyan.service;

import com.cskaoyan.bean.MarketGoodsExample;
import com.cskaoyan.bean.MarketGoodsProductExample;
import com.cskaoyan.bean.MarketOrderExample;
import com.cskaoyan.bean.MarketUserExample;
import com.cskaoyan.bean.vo.DashBoardVo;
import com.cskaoyan.mapper.MarketGoodsMapper;
import com.cskaoyan.mapper.MarketGoodsProductMapper;
import com.cskaoyan.mapper.MarketOrderMapper;
import com.cskaoyan.mapper.MarketUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author yi
 * @date 2022/10/12 23:07
 */
@Service
public class AdminDashboardServiceImpl implements AdminDashboardService {
    @Autowired
    MarketGoodsMapper marketGoodsMapper;
    @Autowired
    MarketUserMapper marketUserMapper;
    @Autowired
    MarketGoodsProductMapper marketGoodsProductMapper;
    @Autowired
    MarketOrderMapper marketOrderMapper;

    @Override
    public DashBoardVo dashboard() {
        MarketGoodsExample marketGoodsExample = new MarketGoodsExample();
        MarketGoodsExample.Criteria criteria1 = marketGoodsExample.createCriteria();
        criteria1.andDeletedEqualTo(false);
        Long goodsTotal = marketGoodsMapper.countByExample(marketGoodsExample);

        MarketUserExample marketUserExample = new MarketUserExample();
        MarketUserExample.Criteria criteria2 = marketUserExample.createCriteria();
        criteria2.andDeletedEqualTo(false);
        Long userTotal = marketUserMapper.countByExample(marketUserExample);

        MarketGoodsProductExample marketGoodsProductExample = new MarketGoodsProductExample();
        MarketGoodsProductExample.Criteria criteria3 = marketGoodsProductExample.createCriteria();
        criteria3.andDeletedEqualTo(false);
        Long productTotal = marketGoodsProductMapper.countByExample(marketGoodsProductExample);

        MarketOrderExample marketOrderExample = new MarketOrderExample();
        MarketOrderExample.Criteria criteria4 = marketOrderExample.createCriteria();
        criteria4.andDeletedEqualTo(false);
        Long orderTotal = marketOrderMapper.countByExample(marketOrderExample);

        DashBoardVo dashBoardVo = new DashBoardVo();

        dashBoardVo.setGoodsTotal(goodsTotal);
        dashBoardVo.setUserTotal(userTotal);
        dashBoardVo.setProductTotal(productTotal);
        dashBoardVo.setOrderTotal(orderTotal);

        return dashBoardVo;
    }
}
